﻿using System.Collections.Generic;
using StringExt;
using NUnit.Framework;

namespace DictionaryExt.Test {

    [TestFixture]
    public class ToDictionaryValidPattern {

        [Test]
        public void With1Token() {
            const string s = "a=1";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.IsTrue(result.ContainsKey("a"));
            Assert.AreEqual("1", result["a"]);
        }

        [Test]
        public void With1TokenAndBlanks() {
            const string s = "a = 1";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.IsTrue(result.ContainsKey("a "));
            Assert.AreEqual(" 1", result["a "]);
        }

        [Test]
        public void With1TokenAndBlanksDeleted() {
            const string s = "a = 1";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.Yes);
            Assert.IsTrue(result.ContainsKey("a"));
            Assert.AreEqual("1", result["a"]);
        }

        [Test]
        public void With2Token() {
            const string s = "a=1;bb=22";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.IsTrue(result.ContainsKey("a"));
            Assert.AreEqual("1", result["a"]);
            Assert.IsTrue(result.ContainsKey("bb"));
            Assert.AreEqual("22", result["bb"]);

        }

        [Test]
        public void With2TokenAndBlanks() {
            const string s = "a=1; bb = 22";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.IsTrue(result.ContainsKey("a"));
            Assert.AreEqual("1", result["a"]);
            Assert.IsTrue(result.ContainsKey(" bb "));
            Assert.AreEqual(" 22", result[" bb "]);

        }

        [Test]
        public void With2TokenAndBlanksDeleted() {
            const string s = "a=1; bb = 22";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.Yes);
            Assert.IsTrue(result.ContainsKey("a"));
            Assert.AreEqual("1", result["a"]);
            Assert.IsTrue(result.ContainsKey("bb"));
            Assert.AreEqual("22", result["bb"]);
        }

        [Test]
        public void With2TokenAndBlanksInsideValuesAndBlanksDeleted() {
            const string s = "a=1; b b = 2 2";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.Yes);
            Assert.IsTrue(result.ContainsKey("a"));
            Assert.AreEqual("1", result["a"]);
            Assert.IsTrue(result.ContainsKey("b b"));
            Assert.AreEqual("2 2", result["b b"]);
        }
    }
}
